<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QWidgetAction Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QWidgetAction Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QWidgetAction class extends <a href="qaction.html">QAction</a> by an interface for inserting custom
widgets into action based containers, such as toolbars. <a href="#details">More...</a></p>

<p>Inherits <a href="qaction.html">QAction</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qwidgetaction.html#QWidgetAction">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />list-of-QWidget <b><a href="qwidgetaction.html#createdWidgets">createdWidgets</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qwidgetaction.html#createWidget">createWidget</a></b> (<i>self</i>, QWidget&#160;<i>parent</i>)</li><li><div class="fn" />QWidget <b><a href="qwidgetaction.html#defaultWidget">defaultWidget</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qwidgetaction.html#deleteWidget">deleteWidget</a></b> (<i>self</i>, QWidget&#160;<i>widget</i>)</li><li><div class="fn" />bool <b><a href="qwidgetaction.html#event">event</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" />bool <b><a href="qwidgetaction.html#eventFilter">eventFilter</a></b> (<i>self</i>, QObject, QEvent)</li><li><div class="fn" /><b><a href="qwidgetaction.html#releaseWidget">releaseWidget</a></b> (<i>self</i>, QWidget&#160;<i>widget</i>)</li><li><div class="fn" />QWidget <b><a href="qwidgetaction.html#requestWidget">requestWidget</a></b> (<i>self</i>, QWidget&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qwidgetaction.html#setDefaultWidget">setDefaultWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QWidgetAction class extends <a href="qaction.html">QAction</a> by an interface for inserting custom
widgets into action based containers, such as toolbars.</p>
<p>Most actions in an application are represented as items in menus
or buttons in toolbars. However sometimes more complex widgets are
necessary. For example a zoom action in a word processor may be
realized using a <a href="qcombobox.html">QComboBox</a> in a
<a href="qtoolbar.html">QToolBar</a>, presenting a range of
different zoom levels. <a href="qtoolbar.html">QToolBar</a>
provides <a href="qtoolbar.html#insertWidget">QToolBar.insertWidget</a>() as
convenience function for inserting a single widget. However if you
want to implement an action that uses custom widgets for
visualization in multiple containers then you have to subclass
QWidgetAction.</p>
<p>If a QWidgetAction is added for example to a <a href="qtoolbar.html">QToolBar</a> then <a href="qwidgetaction.html#createWidget">QWidgetAction.createWidget</a>()
is called. Reimplementations of that function should create a new
custom widget with the specified parent.</p>
<p>If the action is removed from a container widget then <a href="qwidgetaction.html#deleteWidget">QWidgetAction.deleteWidget</a>()
is called with the previously created custom widget as argument.
The default implementation hides the widget and deletes it using
<a href="qobject.html#deleteLater">QObject.deleteLater</a>().</p>
<p>If you have only one single custom widget then you can set it as
default widget using <a href="qwidgetaction.html#setDefaultWidget">setDefaultWidget</a>(). That
widget will then be used if the action is added to a <a href="qtoolbar.html">QToolBar</a>, or in general to an action container
that supports QWidgetAction. If a QWidgetAction with only a default
widget is added to two toolbars at the same time then the default
widget is shown only in the first toolbar the action was added to.
QWidgetAction takes over ownership of the default widget.</p>
<p>Note that it is up to the widget to activate the action, for
example by reimplementing mouse event handlers and calling <a href="qaction.html#trigger">QAction.trigger</a>().</p>
<p><b>Mac OS X</b>: If you add a widget to a menu in the
application's menu bar on Mac OS X, the widget will be added and it
will function but with some limitations:</p>
<ol class="1">
<li>The widget is reparented away from the <a href="qmenu.html">QMenu</a> to the native menu view. If you show the
menu in some other place (e.g. as a popup menu), the widget will
not be there.</li>
<li>Focus/Keyboard handling of the widget is not possible.</li>
<li>Due to Apple's design, mouse tracking on the widget currently
does not work.</li>
<li>Connecting the <a href="qaction.html#triggered">triggered</a>()
signal to a slot that opens a modal dialog will cause a crash in
Mac OS X 10.4 (known bug acknowledged by Apple), a workaround is to
use a QueuedConnection instead of a DirectConnection.</li>
</ol>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QWidgetAction" />QWidgetAction.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an action with <i>parent</i>.</p>


<h3 class="fn"><a name="createdWidgets" />list-of-QWidget QWidgetAction.createdWidgets (<i>self</i>)</h3><p>Returns the list of widgets that have been using <a href="qwidgetaction.html#createWidget">createWidget</a>() and are
currently in use by widgets the action has been added to.</p>


<h3 class="fn"><a name="createWidget" /><a href="qwidget.html">QWidget</a> QWidgetAction.createWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>This function is called whenever the action is added to a
container widget that supports custom widgets. If you don't want a
custom widget to be used as representation of the action in the
specified <i>parent</i> widget then 0 should be returned.</p>
<p><b>See also</b> <a href="qwidgetaction.html#deleteWidget">deleteWidget</a>().</p>


<h3 class="fn"><a name="defaultWidget" /><a href="qwidget.html">QWidget</a> QWidgetAction.defaultWidget (<i>self</i>)</h3><p>Returns the default widget.</p>
<p><b>See also</b> <a href="qwidgetaction.html#setDefaultWidget">setDefaultWidget</a>().</p>


<h3 class="fn"><a name="deleteWidget" />QWidgetAction.deleteWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>widget</i>)</h3><p>The <i>widget</i> argument has it's ownership transferred to Qt.</p><p>This function is called whenever the action is removed from a
container widget that displays the action using a custom
<i>widget</i> previously created using <a href="qwidgetaction.html#createWidget">createWidget</a>(). The default
implementation hides the <i>widget</i> and schedules it for
deletion using <a href="qobject.html#deleteLater">QObject.deleteLater</a>().</p>
<p><b>See also</b> <a href="qwidgetaction.html#createWidget">createWidget</a>().</p>


<h3 class="fn"><a name="event" />bool QWidgetAction.event (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p>


<h3 class="fn"><a name="eventFilter" />bool QWidgetAction.eventFilter (<i>self</i>, <a href="qobject.html">QObject</a>, <a href="qevent.html">QEvent</a>)</h3><p>Reimplemented from <a href="qobject.html#eventFilter">QObject.eventFilter</a>().</p>


<h3 class="fn"><a name="releaseWidget" />QWidgetAction.releaseWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>widget</i>)</h3><p>The <i>widget</i> argument</p><p>Releases the specified <i>widget</i>.</p>
<p>Container widgets that support actions call this function when a
widget action is removed.</p>
<p><b>See also</b> <a href="qwidgetaction.html#requestWidget">requestWidget</a>(), <a href="qwidgetaction.html#deleteWidget">deleteWidget</a>(), and <a href="qwidgetaction.html#defaultWidget">defaultWidget</a>().</p>


<h3 class="fn"><a name="requestWidget" /><a href="qwidget.html">QWidget</a> QWidgetAction.requestWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Returns a widget that represents the action, with the given
<i>parent</i>.</p>
<p>Container widgets that support actions can call this function to
request a widget as visual representation of the action.</p>
<p><b>See also</b> <a href="qwidgetaction.html#releaseWidget">releaseWidget</a>(), <a href="qwidgetaction.html#createWidget">createWidget</a>(), and <a href="qwidgetaction.html#defaultWidget">defaultWidget</a>().</p>


<h3 class="fn"><a name="setDefaultWidget" />QWidgetAction.setDefaultWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Sets <i>widget</i> to be the default widget. The ownership is
transferred to <a href="qwidgetaction.html">QWidgetAction</a>.
Unless <a href="qwidgetaction.html#createWidget">createWidget</a>()
is reimplemented by a subclass to return a new widget the default
widget is used when a container widget requests a widget through
<a href="qwidgetaction.html#requestWidget">requestWidget</a>().</p>
<p><b>See also</b> <a href="qwidgetaction.html#defaultWidget">defaultWidget</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2011</td><td align="right" width="25%">Qt&#160;4.8.0</td></tr></table></div></address></body></html>